﻿namespace DeltaGroup.WheelOfJeopardy.UI.Commands
{
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Input;

    using DeltaGroup.WheelOfJeopardy.ChallengeManager;
    using DeltaGroup.WheelOfJeopardy.Model;
    using DeltaGroup.WheelOfJeopardy.UI.Screens;
    using DeltaGroup.WheelOfJeopardy.UI.ViewModel;

    public class SaveChallengesCommand : LoadUserControlCommand<GameMenu>
    {
        #region Methods

        /// <summary>
        /// Loads the specified window.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <param name="executedRoutedEventArgs">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
        public override void Load(Window window, ExecutedRoutedEventArgs executedRoutedEventArgs)
        {
            base.Load(window, executedRoutedEventArgs);

            var challengeEditModel = executedRoutedEventArgs.Parameter as ChallengeEditModel;

            string saveFileName = challengeEditModel.NewChallengeFile;
            if(string.IsNullOrWhiteSpace(challengeEditModel.NewChallengeFile))
            {
                saveFileName = challengeEditModel.SelectedChallengeFile;
            }

            ChallengeManager challengeManager = ChallengeManager.GetInstance();
            challengeManager.WriteChallengeSetToFile(saveFileName, challengeEditModel.extractChallengeSet());
        }

        /// <summary>
        /// Extracts the synonyms.
        /// </summary>
        /// <returns></returns>
        private List<Synonym> ExtractSynonyms()
        {
            return new List<Synonym>();
        }

        #endregion Methods
    }
}